<template>
  <div class="app-container">
    <el-form :model="queryParams" :rules="rules2" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
	  
	  <el-form-item label="学校" prop="sjXxid">
	    <el-select v-model="queryParams.sjXxid" @change="schoolChange" placeholder="请选择学校" :disabled="isXxidFlag">
	      <el-option
	        v-for="d in dept_self"
	        :key="d.value"
	        :label="d.label"
	        :value="d.value"
	      />
	    </el-select>
	  </el-form-item>	
	  <el-form-item label="班级" prop="sjBjid">
	    <el-select v-model="queryParams.sjBjid" @change="classChange" placeholder="请选择班级">
	  	<el-option
	  	  v-for="c in classList2"
	  	  :key="c.value"
	  	  :label="c.label"
	  	  :value="c.value"
	  	/>
	    </el-select>
	  </el-form-item>
	  
      <el-form-item label="年级" prop="sjNjid">
        <el-select v-model="queryParams.sjNjid" placeholder="年级" disabled>
          <el-option
            v-for="dict in tc_nj"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
		
      </el-form-item>
      <el-form-item label="体测项目" prop="sjTcxmid">
		  <el-select v-model="queryParams.sjTcxmid" placeholder="体测项目"   @change="handleQuery" clearable>
			<el-option
			  v-for="c in projectList"
			  :key="c.id"
			  :label="c.xmMc"
			  :value="c.id"
			/>
		  </el-select>
      </el-form-item>
	  <el-form-item label="证件号" prop="sjSfz">
	    <el-input
	      v-model="queryParams.sjSfz"
	      placeholder="请输入证件号"
	      clearable
	      @keyup.enter="handleQuery"
	    />
	  </el-form-item>
	  <el-form-item label="姓名" prop="sjSname">
	    <el-input
	      v-model="queryParams.sjSname"
	      placeholder="请输入姓名"
	      clearable
	      @keyup.enter="handleQuery"
	    />
	  </el-form-item>
<!-- 	  <el-form-item label="学号" prop="sjXh">
	    <el-input
	      v-model="queryParams.sjXh"
	      placeholder="请输入学号"
	      clearable
	      @keyup.enter="handleQuery"
	    />
	  </el-form-item> -->
	  
	  <el-row style="justify-content: right;">
		  <el-form-item>
			<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
			<el-button icon="Refresh" @click="resetQuery">重置</el-button>
		  </el-form-item>
	  </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['tc:tcsj:add']"
        >新增</el-button>
      </el-col>
	  <el-col :span="1.5">
	          <el-button
	            type="success"
	            plain
	            icon="Edit"
	            @click="handleUpdatePL"
	            v-hasPermi="['tc:tcsj:edit']"
	          >数据批量优化</el-button>
		</el-col>
<!--	  <el-col :span="1.5">
	    <el-button
	      type="danger"
	      plain
	      icon="Delete"
	      :disabled="multiple"
	      @click="handleDelete"
	      v-hasPermi="['tc:tcsj:remove']"
	    >删除</el-button>
	  </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['tc:tcsj:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['tc:tcsj:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table  :show-overflow-tooltip="true" v-loading="loading" :data="tcsjList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="ID" align="center" prop="id" /> -->
      <el-table-column type="index" align="center" prop="id" />
      <el-table-column label="学生" align="center" prop="sjSname" width="150" />
	  <el-table-column label="性别" align="center" prop="sjSex" >
	    <template #default="scope">
	      <dict-tag :options="sys_user_sex" :value="scope.row.sjSex"/>
	    </template>
	  </el-table-column>
	  
	  <el-table-column label="得分级别" align="center" prop="sjDfjb"  width="120" >
	  		<template #default="scope">
	  			<el-tag type="warning">{{ scope.row.sjDfjb }}</el-tag>
	    </template>
	  </el-table-column>
	  <el-table-column label="体测得分" align="center" prop="sjFs" >
	  		<template #default="scope">
	  			<el-tag type="danger">{{ scope.row.sjFs }}</el-tag>
	    </template>
	  </el-table-column>
	  <el-table-column label="体测数值" align="center" prop="sjDfsz" >
	  		<template #default="scope">
	  			<el-tag>{{ isDecimalZero(scope.row.sjDfsz)?parseInt(scope.row.sjDfsz):scope.row.sjDfsz }} / {{scope.row.sjUnit}}</el-tag>
	    </template>
	  </el-table-column>
	  <!-- <el-table-column label="单位" align="center" prop="sjUnit" /> -->
      <el-table-column label="体测项目" align="center" prop="sjTcxmid" width="160">
	    <template #default="scope">
			<el-tag>
				<span  v-for="c in projectList"
				  :key="c.id"
				  :label="c.xmMc"
				  :value="c.id"
				>{{scope.row.sjTcxmid==c.id?c.xmMc:''}}</span>
			</el-tag>
	      <!-- <dict-tag :options="projectList" :value="scope.row.sjTcxmid"/> -->
	    </template>
	  </el-table-column>
	  
      <el-table-column label="学校" align="center" prop="sjXxid" width="150" >
	  
	    <template #default="scope">
			
				<span  v-for="c in dept_self"
				  :key="c.value"
				  :label="c.label"
				  :value="c.value"
				>{{scope.row.sjXxid==c.value?c.label:''}}</span>
	      <!-- <dict-tag :options="dept_self" :value="scope.row.sjXxid"/> -->
		  
		  
	    </template>
	  
	  </el-table-column>
      <el-table-column label="年级" align="center" prop="sjNjid" width="100" :show-overflow-tooltip="true">
        <template #default="scope">
          <dict-tag :options="tc_nj" :value="scope.row.sjNjid"/>
        </template>
      </el-table-column>
      <el-table-column label="证件号" align="center" prop="sjSfz" min-width="180" />
      <el-table-column label="体测名称" align="center" prop="tcnameid"  width="200">
	    <template #default="scope">
			<span  v-for="c in tcnameList"
			  :key="c.id"
			  :label="c.tcname"
			  :value="c.id"
			>{{scope.row.tcnameid==c.id?c.tcname:''}}</span>
		  
	    </template>
	  </el-table-column>
      <el-table-column label="评分标准" align="center" prop="sjTcfl"  width="200">
	    <template #default="scope">
			<span  v-for="c in projecttypeList"
			  :key="c.id"
			  :label="c.xmflTitle"
			  :value="c.id"
			>{{scope.row.sjTcfl==c.id?c.xmflTitle:''}}</span>
		  
	    </template>
	  </el-table-column>
      <!-- <el-table-column label="基础数据" align="center" prop="sjJcsjid" /> -->
      
    
      <el-table-column label="体测时间" align="center" prop="sjTcsj" width="180">
        <template #default="scope">
          <!-- <span>{{ parseTime(scope.row.sjTcsj, '{y}-{m}-{d}') }}</span> -->
          <span>{{scope.row.sjTcsj }}</span>
        </template>
      </el-table-column>
      <el-table-column label="体测教师" align="center" prop="sjTcjs" />
	  <el-table-column label="设备" align="center" prop="sjSbid" />
      <!-- <el-table-column label="创建人" align="center" prop="sjCreateby" /> -->
<!--      <el-table-column label="创建时间" align="center" prop="sjCreate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.sjCreate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="修改人" align="center" prop="sjUpdateby" />
      <el-table-column label="修改时间" align="center" prop="sjUpdate" />
      <!-- <el-table-column label="原始编号" align="center" prop="sjData" /> -->
      <!-- <el-table-column label="学号" align="center" prop="sjXh" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template #default="scope">
          <el-button link type="success" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['tc:tcsj:edit']">优化</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['tc:tcsj:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改体测项目数据对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="tcsjRef" :model="form" :rules="rules" label-width="80px">
		  
		  <el-form-item label="学校" prop="sjXxid">
		      <el-select v-model="form.sjXxid" @change="schoolChangeAU" placeholder="请选择学校" :disabled="isXxidFlag">
		        <el-option
		          v-for="d in dept_self"
		          :key="d.value"
		          :label="d.label"
		          :value="d.value"
		        />
		      </el-select>
		  </el-form-item>	
		  <el-form-item label="班级" prop="sjBjid">
		  	<el-select v-model="form.sjBjid" placeholder="请选择班级" @change="classChangeAU"  :disabled="auform">
		  	<el-option
		  	  v-for="c in classList3"
		  	  :key="c.value"
		  	  :label="c.label"
		  	  :value="c.value"
		  	/>
		  	</el-select>
		  </el-form-item>
		  
        <el-form-item label="年级" prop="sjNjid">
          <el-select v-model="form.sjNjid" placeholder="请选择年级" disabled>
            <el-option
              v-for="dict in tc_nj"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
		
		<el-form-item label="学生" prop="sjXsid">
		  <el-select v-model="form.sjXsid" filterable placeholder="请选择学生" :disabled="auform">
		    <el-option
		      v-for="d in studentList"
		      :key="d.id"
		      :label="d.xsName"
		      :value="d.id"
		    ></el-option>
		  </el-select>
		</el-form-item>
		
		<el-form-item label="评分标准" prop="sjTcfl">
			<el-select v-model="form.sjTcfl" @change="tcflChange" filterable placeholder="请选择评分标准">
			<el-option
			  v-for="c in projecttypeList"
			  :key="c.id"
			  :label="c.xmflTitle"
			  :value="c.id"
			/>
			</el-select>
		</el-form-item>
		<el-form-item label="体测项目" prop="sjTcxmid">
			<el-select v-model="form.sjTcxmid" filterable placeholder="请选择体测项目" :disabled="auform">
			<el-option
			  v-for="c in projectList2"
			  :key="c.id"
			  :label="c.xmMc"
			  :value="c.id"
			/>
			</el-select>
		</el-form-item>
		<el-form-item label="体测数值" prop="sjDfsz">
		  <el-input v-model="form.sjDfsz" type="number" placeholder="体测数值"/>
		</el-form-item>
		
        <el-form-item label="设备id" prop="sjSbid">
          <el-input v-model="form.sjSbid" placeholder="请输入设备id" :disabled="auform" />
        </el-form-item>
        <el-form-item label="证件号" prop="sjSfz">
          <el-input v-model="form.sjSfz" placeholder="请输入证件号"  :disabled="auform"/>
        </el-form-item>
<!--        <el-form-item label="学号" prop="sjXh">
          <el-input v-model="form.sjXh" placeholder="请输入学号" />
        </el-form-item> -->
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
	<!-- 批量添加或修改体测项目数据对话框 -->
	    <el-dialog :title="title2" v-model="open2" width="500px" append-to-body>
	      <el-form ref="tcsjRef2" :model="form" :rules="rules3" label-width="80px">
			  
			  <el-form-item label="学校" prop="sjXxid">
			      <el-select v-model="form.sjXxid" @change="schoolChangeAU" placeholder="请选择学校" :disabled="isXxidFlag">
			        <el-option
			          v-for="d in dept_self"
			          :key="d.value"
			          :label="d.label"
			          :value="d.value"
			        />
			      </el-select>
			  </el-form-item>	
			  <el-form-item label="班级" prop="sjBjid">
			  	<el-select v-model="form.sjBjid" placeholder="请选择班级" @change="classChangeAU">
			  	<el-option
			  	  v-for="c in classList3"
			  	  :key="c.value"
			  	  :label="c.label"
			  	  :value="c.value"
			  	/>
			  	</el-select>
			  </el-form-item>
			  
	        <el-form-item label="年级" prop="sjNjid">
	          <el-select v-model="form.sjNjid" placeholder="请选择年级" disabled>
	            <el-option
	              v-for="dict in tc_nj"
	              :key="dict.value"
	              :label="dict.label"
	              :value="dict.value"
	            ></el-option>
	          </el-select>
	        </el-form-item>
			<el-form-item label="评分标准" prop="sjTcfl">
				<el-select v-model="form.sjTcfl" @change="tcflChange" filterable placeholder="请选择评分标准">
				<el-option
				  v-for="c in projecttypeList"
				  :key="c.id"
				  :label="c.xmflTitle"
				  :value="c.id"
				/>
				</el-select>
			</el-form-item>
			
			<el-form-item label="体测项目" prop="sjTcxmid">
				<el-select v-model="form.sjTcxmid" filterable placeholder="请选择体测项目">
				<el-option
				  v-for="c in projectList2"
				  :key="c.id"
				  :label="c.xmMc"
				  :value="c.id"
				/>
				</el-select>
			</el-form-item>
			<el-form-item label="数据优化" prop="sjDfsz">
			  <el-input v-model="form.sjDfsz" type="number" placeholder="上调或下调体测数值"/>
			  <el-text type="danger" style="font-size: 80%;">说明：在原基础上 上调 或 下调 如:上调(5) 下调(-5)</el-text>
			</el-form-item>
	      </el-form>
	      <template #footer>
	        <div class="dialog-footer">
	          <el-button type="primary" @click="submitForm2">确 定</el-button>
	          <el-button @click="cancel2">取 消</el-button>
	        </div>
	      </template>
	    </el-dialog>
  </div>
</template>

<script setup name="Tcsj">
import { listTcsj, getTcsj, delTcsj, addTcsj, updateTcsj,updateTcsjPL } from "@/api/tc/tcsj";
import { checkPermi, checkRole } from "@/utils/permission"; // 1. 导入权限判断函数
import { listDept } from "@/api/system/dept";
import { listStudent } from "@/api/tc/student";
import { listClass } from "@/api/tc/class";
import { listProject} from "@/api/tc/project";
import { listTctype} from "@/api/tc/tctype";
import { listTcname} from "@/api/tc/tcname";
import useUserStore from '@/store/modules/user';
var userStore=useUserStore();

const { proxy } = getCurrentInstance();
const { tc_nj,sys_user_sex } = proxy.useDict('tc_nj','sys_user_sex');

const tcsjList = ref([]);
const open = ref(false);
const open2 = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const title2 = ref("");

const projecttypeList = ref([]);
const projectList = ref([]);
const projectList2 = ref([]);
const studentList = ref([]);
const classList = ref([]);
const classList2 = ref([]);
const classList3 = ref([]);
const dept_self = ref([]);
const tcnameList = ref([]);
const isXxidFlag=ref(false);
const auform=ref(true);
const tmpGetPar=ref({"pageNum": 1,"pageSize": 999});
const tmpProPar={pageNum: 1,pageSize: 999};
const tmpProTypePar={pageNum: 1,pageSize: 999,xmflStatus:'1'};

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sjXsid: null,
    sjXxid: null,
    sjBjid: null,
    sjNjid: null,
    sjTcxmid: null,
    sjTcfl: null,
    sjJcsjid: null,
    sjSbid: null,
    sjFs: null,
    sjDfjb: null,
    sjDfsz: null,
    sjTcsj: null,
    sjTcjs: null,
    sjCreate: null,
    sjCreateby: null,
    sjUpdate: null,
    sjUpdateby: null,
    sjSfz: null,
    sjXh: null
  },
  rules: {
	  sjXxid: [
	    { required: true, message: "学校不能为空", trigger: "change" }
	  ],
	  sjBjid: [
	    { required: true, message: "班级不能为空", trigger: "change" }
	  ],
	  sjNjid: [
	    { required: true, message: "年级不能为空", trigger: "change" }
	  ],
	  sjXsid: [
	    { required: true, message: "学生不能为空", trigger: "change" }
	  ],
	  sjTcxmid: [
	    { required: true, message: "体测项目不能为空", trigger: "change" }
	  ],
	  sjTcfl: [
	    { required: true, message: "评分标准不能为空", trigger: "change" }
	  ],
	  sjDfsz: [
	    { required: true, message: "体测数值不能为空", trigger: "change" }
	  ]
	  
  },
  rules2: {
    sjBjid: [
      { required: true, message: "班级不能为空", trigger: "change" }
    ],
    sjXxid: [
      { required: true, message: "学校不能为空", trigger: "change" }
    ],
  },
  rules3: {
	  sjXxid: [
	    { required: true, message: "学校不能为空", trigger: "change" }
	  ],
	  sjBjid: [
	    { required: true, message: "班级不能为空", trigger: "change" }
	  ],
	  sjNjid: [
	    { required: true, message: "年级不能为空", trigger: "change" }
	  ],
	  sjTcxmid: [
	    { required: true, message: "体测项目不能为空", trigger: "change" }
	  ],
	  sjTcfl: [
	    { required: true, message: "评分标准不能为空", trigger: "change" }
	  ],
	  sjDfsz: [
	    { required: true, message: "体测数值不能为空", trigger: "blur" }
	  ]
	  
  },
});

const { queryParams, form, rules, rules2,rules3 } = toRefs(data);


 onMounted(() => {
      // console.log('组件已经挂载')
	getDeptInfo();  
	getTctypeList();
	getTcnameList();
	// getClassList();
	
	// getList();
 })
 /** 查询评分标准列表 */
 function getTctypeList() {
   loading.value = true;
   listTctype(tmpProTypePar).then(response => {
     projecttypeList.value = response.rows;
     loading.value = false;
 	 getProjectList();
   });
 }
 function getDeptInfo(){
 		// console.log(userStore.user)
 		if(checkRole(['admin','common'])){
 			listDept(tmpGetPar).then(response => {
 			  	response.data.forEach(function (element) {
 			  	  // 遍历数组，对每个元素进行操作
 				   if(element.xxlevel !=null && element.xxlevel != ''){
 						dept_self.value.push({"value":element.deptId,"label":element.deptName});
 				   }
 			  	});
 				queryParams.value.sjXxid=dept_self.value[0].value;
 				getClassList(null);
 			});
 			isXxidFlag.value=false;
 		}else{
 			dept_self.value.push({"value":userStore.user.deptId,"label":userStore.user.dept.deptName});
 			queryParams.value.sjXxid=dept_self.value[0].value;
 			isXxidFlag.value=true;
 			getClassList(queryParams.value.sjXxid);
 		}
 }
 
 function getClassList(bjid){
 	// if(checkRole(['admin','common'])){
 	// 	bjid=null;;
 	// }else{
 	// 	bjid=userStore.user.deptId;
 	// }
 	listClass({"pageNum": 1,"pageSize": 500,"bjXxid" : bjid}).then(response => {
 		response.rows.forEach(function (el) {
 		  // 遍历数组，对每个元素进行操作
 			classList.value.push({"value":el.id,"label":el.bjName,"xxid":el.bjXxid,"nj":el.bjNj});
 		});
 		if(classList.value.length > 0){
 			queryParams.value.sjBjid=classList.value[0].value;
 			schoolChange(classList.value[0].xxid)
 			schoolChangeAU(classList.value[0].xxid)
 		}
 		// getList();
 	});
 }
 
 /** 查询体测项目列表 */
 function getProjectList() {
   loading.value = true;
   listProject(tmpProPar).then(response => {
     projectList.value = response.rows;
     projectList2.value = response.rows;
     loading.value = false;
   });
 }
 /** 查询体测名称列表 */
 function getTcnameList() {
   listTcname(tmpGetPar).then(response => {
     tcnameList.value = response.rows;
   });
 }
 /** 查询学生管理列表 */
 function getStudentList(xxid,bjid) {
    if(xxid==null || bjid==null || xxid=='' || bjid==''){
		// proxy.$modal.msgSuccess("");
		studentList.value=null;
	}else{
		loading.value = true;
		let tmp={pageNum: 1,pageSize: 1000,xsClassj: bjid,xsSchool: xxid};
		studentList.value=listStudent(tmp).then(response => {
		  studentList.value = response.rows;
		  loading.value = false;
		});
	}
 }
 
 function schoolChange(e){
 	classList2.value= classList.value.filter(function(currentValue,index,arr){
 		// console.log(currentValue)
 		return currentValue.xxid == e ;
 	});
 	
 	if(classList2.value.length==0){
 		queryParams.value.sjBjid=null;
		queryParams.value.sjNjid=null;
 	}else{
 		queryParams.value.sjBjid=classList2.value[0].value;
		queryParams.value.sjNjid=classList2.value[0].nj;
 	}
	handleQuery();
 } 
 function classChange(e){
	 // console.log(classList2.value)
	 let tmp= classList2.value.filter(function(currentValue,index,arr){
	 	// console.log(currentValue)
	 	return currentValue.value == e ;
	 });
	queryParams.value.sjNjid=tmp[0].nj;
 }
 
 function schoolChangeAU(e){
 	classList3.value= classList.value.filter(function(currentValue,index,arr){
 		// console.log(currentValue)
 		return currentValue.xxid == e ;
 	});
 	
 	if(classList3.value.length==0){
 		form.value.sjBjid=null;
 	}else{
 		form.value.sjBjid=classList3.value[0].value;
 	}
	classChangeAU(form.value.sjBjid)
 }
 
 function classChangeAU(e){
	 // console.log(e)
 	 // console.log(classList2.value)
 	 let tmp= classList2.value.filter(function(currentValue,index,arr){
 	 	// console.log(currentValue)
 	 	return currentValue.value == e ;
 	 });
	 if(tmp.length==0){
		form.value.sjNjid=null;
	 }else{
		form.value.sjNjid=tmp[0].nj;
	 }
	 
	
	getStudentList(form.value.sjXxid,form.value.sjBjid);
 }
 function tcflChange(e){
	 form.value.sjTcxmid=null;
	 if(e==null || e==''){
	   projectList2.value=projectList.value;
	 }else{
	  projectList2.value=[];
	  projecttypeList.value.forEach((item)=>{
	 	 if(item.id==e){
	 		// console.log(item.tcProjectTpList)
	 		item.tcProjectTpList.forEach((item2)=>{
	 			let a=projectList.value.filter(function(currentValue,index,arr){
	 				return currentValue.id == item2.projectid ;
	 			});
	 			projectList2.value.push(a[0])
	 			// console.log(item2)
	 		})
	 	 }
	  })
	 }
 }
 
 
 

/** 查询体测项目数据列表 */
function getList() {
  loading.value = true;
	  // console.log(queryParams.value))
  listTcsj(queryParams.value).then(response => {
	  // console.log(response.rows)
    tcsjList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}
// 取消按钮
function cancel2() {
  open2.value = false;
  reset();
}
// 表单重置
function reset() {
  form.value = {
    id: null,
    sjXsid: null,
    sjXxid: dept_self.value[0].value,
	sjBjid: classList3.value.length>0?classList3.value[0].value:null,
    sjNjid: null,
    sjTcxmid: null,
    sjTcfl: null,
    sjJcsjid: null,
    sjSbid: null,
    sjFs: null,
    sjDfjb: null,
    sjDfsz: null,
    sjTcsj: null,
    sjTcjs: null,
    sjCreate: null,
    sjCreateby: null,
    sjUpdate: null,
    sjUpdateby: null,
    sjSfz: null,
    sjSname: null,
    sjXh: null
  };
  schoolChangeAU(dept_self.value[0].value);
  classChangeAU(classList3.value[0].value);
  getStudentList(dept_self.value[0].value,classList3.value[0].value);
  proxy.resetForm("tcsjRef");
  proxy.resetForm("tcsjRef2");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value.sjXxid=dept_self.value[0].value;
  schoolChange(classList.value[0].xxid)
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  auform.value=false;
  open.value = true;
  title.value = "添加体测项目数据";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  isXxidFlag.value=true;
  auform.value=true;
  const _id = row.id || ids.value
  getTcsj(_id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改体测项目数据";
  });
}

/** 批量修改按钮操作 */
function handleUpdatePL() {
  reset();
  open2.value = true;
  title2.value = "数据批量优化";
  // console.log(form.value)
  // getTcsj(_id).then(response => {
  //   form.value = response.data;
  //   open.value = true;
  //   title.value = "修改体测项目数据";
  // });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["tcsjRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
		  console.log(form.value)
        updateTcsj(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addTcsj(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}
/** 提交按钮 */
function submitForm2() {
  proxy.$refs["tcsjRef2"].validate(valid => {
    if (valid) {
		// console.log(form.value)
        updateTcsjPL(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open2.value = false;
          getList();
        });
    }
  });
}
/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除体测项目数据编号为"' + _ids + '"的数据项？').then(function() {
    return delTcsj(_ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('tc/tcsj/export', {
    ...queryParams.value
  }, `tcsj_${new Date().getTime()}.xlsx`)
}





function isDecimalZero(num) {
    // 将数字转换为字符串
    const numStr = num.toString();
    // 提取小数点后的部分
    const decimalPart = numStr.split('.')[1];
    // 检查小数点后是否全是0
    return /^0*$/.test(decimalPart);
}
</script>
